apiVersion: px.dev/v1alpha1
kind: Vizier
metadata:
  name: {{ .Values.name }}
  namespace: {{ .Release.Namespace }}
spec:
  {{- if .Values.version }}
  version: {{ .Values.version }}
  {{- end }}
  deployKey: {{ .Values.deployKey }}
  {{- if .Values.customDeployKeySecret }}
  customDeployKeySecret: {{ .Values.customDeployKeySecret }}
  {{- end }}
  cloudAddr: {{ .Values.cloudAddr }}
  disableAutoUpdate: {{ .Values.disableAutoUpdate }}
  useEtcdOperator: {{ .Values.useEtcdOperator }}
  {{- if (.Values.global).cluster }}
  clusterName: {{ .Values.global.cluster }}
  {{- else if .Values.clusterName }}
  clusterName: {{ .Values.clusterName }}
  {{- end }}
  {{- if .Values.devCloudNamespace }}
  devCloudNamespace: {{ .Values.devCloudNamespace }}
  {{- end }}
  {{- if .Values.pemMemoryLimit }}
  pemMemoryLimit: {{ .Values.pemMemoryLimit }}
  {{- end }}
  {{- if .Values.pemMemoryRequest }}
  pemMemoryRequest: {{ .Values.pemMemoryRequest }}
  {{- end }}
  {{- if .Values.dataAccess }}
  dataAccess: {{ .Values.dataAccess }}
  {{- end }}
  {{- if .Values.patches }}
  patches: {{ .Values.patches | toYaml | nindent 4 }}
  {{- end }}
  {{- if ((.Values.global).images).registry }}
  registry: {{ .Values.global.images.registry }}
  {{- else if .Values.registry }}
  registry: {{ .Values.registry }}
  {{- end}}
  {{- if .Values.autopilot }}
  autopilot: {{ .Values.autopilot }}
  {{- end}}
  {{- if .Values.dataCollectorParams }}
  dataCollectorParams:
    {{- if .Values.dataCollectorParams.datastreamBufferSize }}
    datastreamBufferSize: {{ .Values.dataCollectorParams.datastreamBufferSize }}
    {{- end }}
    {{- if .Values.dataCollectorParams.datastreamBufferSpikeSize }}
    datastreamBufferSpikeSize: {{ .Values.dataCollectorParams.datastreamBufferSpikeSize }}
    {{- end }}
    {{- if .Values.dataCollectorParams.customPEMFlags }}
    customPEMFlags:
    {{- range $key, $value := .Values.dataCollectorParams.customPEMFlags}}
      {{$key}}: "{{$value}}"
    {{- end}}
    {{- end }}
  {{- end}}
  {{- if .Values.leadershipElectionParams }}
  leadershipElectionParams:
    {{- if .Values.leadershipElectionParams.electionPeriodMs }}
    electionPeriodMs: {{ .Values.leadershipElectionParams.electionPeriodMs }}
    {{- end }}
  {{- end }}
  {{- if or .Values.pod.securityContext (or .Values.pod.nodeSelector (or .Values.pod.tolerations (or .Values.pod.annotations (or .Values.pod.labels .Values.pod.resources)))) }}
  pod:
    {{- if .Values.pod.annotations }}
    annotations: {{ .Values.pod.annotations | toYaml | nindent 6 }}
    {{- end }}
    {{- if .Values.pod.labels }}
    labels: {{ .Values.pod.labels | toYaml | nindent 6 }}
    {{- end }}
    {{- if .Values.pod.resources }}
    resources: {{ .Values.pod.resources | toYaml | nindent 6 }}
    {{- end }}
    {{- if .Values.pod.nodeSelector }}
    nodeSelector: {{ .Values.pod.nodeSelector | toYaml | nindent 6 }}
    {{- end }}
    {{- if .Values.pod.tolerations }}
    tolerations: {{ .Values.pod.tolerations | toYaml | nindent 4 }}
    {{- end }}
    {{- if .Values.pod.securityContext }}
    securityContext:
      enabled: {{ .Values.pod.securityContext.enabled }}
      {{- if .Values.pod.securityContext.enabled }}
      {{- if .Values.pod.securityContext.fsGroup }}
      fsGroup: {{ .Values.pod.securityContext.fsGroup }}
      {{- end }}
      {{- if .Values.pod.securityContext.runAsUser }}
      runAsUser: {{ .Values.pod.securityContext.runAsUser }}
      {{- end }}
      {{- if .Values.pod.securityContext.runAsGroup }}
      runAsGroup: {{ .Values.pod.securityContext.runAsGroup }}
      {{- end }}
      {{- end }}
    {{- end }}
  {{- end }}
